package org.ahuanlien.crm.web.controller;

import org.ahuanlien.crm.domain.LossRecord;
import org.ahuanlien.crm.query.LossRecordQueryObject;
import org.ahuanlien.crm.service.ILossRecordService;
import org.ahuanlien.crm.util.JSONResult;
import org.ahuanlien.crm.util.PageResult;
import org.ahuanlien.crm.vo.LossRecordVO;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("lossRecord")
public class LossRecordController {

	@Autowired
	private ILossRecordService lossRecordService;

	//开发失败记录页面
	@RequestMapping("false")
	@RequiresPermissions(value = {"lossRecord:false", "开发失败记录页面"}, logical = Logical.OR)
	public String develop() {
		return "lossRecord/false";
	}

	//客户流失记录页面
	@RequestMapping("loss")
	@RequiresPermissions(value = {"lossRecord:loss", "客户流失记录页面"}, logical = Logical.OR)
	public String followUp() {
		return "lossRecord/loss";
	}

	@RequestMapping("query")
	@RequiresPermissions(value = {"lossRecord:query", "失败记录/流失记录列表"}, logical = Logical.OR)
	@ResponseBody
	public PageResult query(LossRecordQueryObject qo) {
		PageResult result = lossRecordService.Query(qo);
		return result;
	}

	@RequestMapping("saveOrUpdate")
	@RequiresPermissions(value = {"lossRecord:query", "失败记录/流失记录新增/编辑"}, logical = Logical.OR)
	@ResponseBody
	public JSONResult saveOrUpdate(LossRecord lossRecord) {
		try {
			lossRecordService.saveOrUpdate(lossRecord);
		} catch (Exception e) {
			e.printStackTrace();
			return JSONResult.mark("操作失败");
		}
		return JSONResult.success("操作成功");
	}

	//新增开发失败or流失客户记录
	@RequestMapping("insertLossRecord")
	@ResponseBody
	public JSONResult insertLossRecord(LossRecordVO vo) {
		try {
			lossRecordService.insertLossRecord(vo);
		} catch (Exception e) {
			e.printStackTrace();
			return JSONResult.mark("操作失败");
		}
		return JSONResult.success("操作成功");
	}
}
